<?php
namespace app\index\model;
use think\model;
use \think\facade\Cache;
class category extends Model
{
    public static function category()
    {
        $parent=category::
        where('parentid','=',0)
            ->select()->toArray();

        foreach ($parent as $k=>$v){
            $parent1=\think\facade\Db::table('ecm_category')
                ->where('parentid','=',"{$v['id']}")
                ->select()->toArray();
            $parent[$k]['parent1']=$parent1;
        }
        return $parent;
    }

    public static function cate($pid)
    {
        $cate=category::order('sort')
            ->where('parentid',$pid)
            ->select()->toArray();
        if (Cache::has('cate')){
            $all=Cache::get('cate');
        }else{
            $all=category::
            distinct(true)
                ->column('parentid');
            Cache::set('cate',$all,10);
        }
        $all=category::
        column('parentid');
        foreach ($cate as &$v){
            if (in_array($v['id'],$all)){
                $v['next']=1;
            }else{
                $v['next']=0;
            }
        }
        return $cate;

    }
    public static function cate1()
    {
        $cate1=category::order('sort')
            ->where('parentid=0')
            ->select();
        return $cate1;

    }
}